/*希尔排序
 *
 */
#include "shellsort.h"
#include "swap.h"

ShellSort::ShellSort()
{

}

void shellsort(int *array, int length)
{
    if(array==NULL || length<2)
        return;

    int step=length;
    do{
        step=step/3+1;
        for(int i=step;i<length;++i){
            if(array[i]<array[i-step]){
                int tmp=array[i];

                int j;
                for(j=i-step;j>=0 && array[j]>tmp;j-=step)
                    array[j+step]=array[j];

                array[j+step]=tmp;
            }
        }
    }while(step>1);
}
